package cn.xtits.xtf.common.spring.db;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;


public class DynamicSourceRoute extends AbstractRoutingDataSource {

    public static final Logger logger = LoggerFactory.getLogger(DynamicSourceRoute.class);

    /**
     * 选取数据源
     * @return
     */
    @Override
    protected Object determineCurrentLookupKey() {
        Shard shard = DynamicDataSourceShardHolder.getShard();
        if (shard == null)
            return null;
        else
            return shard.getDbName();
    }
}
